package org.rico.quartz.dynamic;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.rico.quartz.dynamic.job.LogJob;
import org.rico.quartz.dynamic.job.PrintJob;

import java.text.ParseException;

/**
 * Created by rico on 2017/9/25.
 */
public class DynamicQuartZ {

    public static void main(String[] args) throws SchedulerException, ParseException {
        Scheduler scheduler = SchedularBuilder.build();

        JobDetail logJobDetail = new JobDetailBuilder("logJob", "logGroup")
                .jobClazz(LogJob.class)
                .build();
        Trigger logTrigger = new TriggerBuilder("logJob", "logGroup")
                .cronExpression("*/5 * * * * ?")
                .build();
        scheduler.scheduleJob(logJobDetail, logTrigger);

        JobDetail printJobDetail = new JobDetailBuilder("printJob", "printGroup")
                .jobClazz(PrintJob.class)
                .build();
        Trigger printTrigger = new TriggerBuilder("printJob", "printGroup")
                .cronExpression("*/5 * * * * ?")
                .build();
        scheduler.scheduleJob(printJobDetail, printTrigger);

        scheduler.start();

    }
}
